/**
 * @param {string} s1
 * @param {string} s2
 * @param {string} s3
 * @return {boolean}
 */
var isInterleave = function (s1, s2, s3) {
  if (s1.length + s2.length != s3.length) return false
  let index1 = 0,
    index2 = 0
  for (let i = 0; i < s3.length; ) {
    if (s3[i] != s1[index1] &&s3[i] != s2[index2]) break
    while (index1 < s1.length) {
      if (s3[i] == s1[index1]) {
        index1++
        i++
      } else break
    }
    while (index2 < s2.length) {
      if (s3[i] == s2[index2]) {
        index2++
        i++
      } else break
    }
  }

  return index1 == s1.length && index2 == s2.length
}

isInterleave('aa', 'ab', 'aaba')
